//
//  ZSHostInfoViewController.m
//  ZhuShou
//
//  Created by zypsusu on 15/12/27.
//  Copyright © 2015年 jw. All rights reserved.
//

#import "ZSHostInfoViewController.h"
#import "JWAnimationManager.h"
#import "ZSHostExchangeViewController.h"

#define CannelHostNameTag 1101

@interface ZSHostInfoViewController ()
@property (weak, nonatomic) IBOutlet UILabel *connectTyoe;
@property (weak, nonatomic) IBOutlet UIButton *resetBtn;
@property (weak, nonatomic) IBOutlet UIButton *exchangeBtn;
@property (weak, nonatomic) IBOutlet UILabel *hostIDLabel;

@property (weak, nonatomic) IBOutlet UILabel *hostName;
@property (nonatomic, strong) JWAnimationManager *am;
@property (weak, nonatomic) IBOutlet UITextField *passwordTextField;

@property (strong, nonatomic) IBOutlet UIView *inputPasswordView;

@property (strong, nonatomic) IBOutlet UIView *hostNameView;
@property (weak, nonatomic) IBOutlet UITextField *hostNameTextField;

@end

@implementation ZSHostInfoViewController

- (IBAction)resetClick:(id)sender {
    self.title = @"恢复出厂设置";
    [self br_alertViewConfirmWithTitle:@" " content:@"恢复出厂设置后将删除所有用户数据,确认要恢复所有出厂设置?" operationIndex:^(NSInteger clickedIndex) {
        if (1 == clickedIndex) {
          [self.am popView:self.inputPasswordView startLocation:JWAnimationLocation_Bottom endLocation:JWAnimationLocation_Center tapMaskBlock:^{
              
          }];
            [self.passwordTextField becomeFirstResponder];
        }
    }];
}

- (IBAction)exchangeHostMachine:(id)sender {
    self.title = @"主机替换";
    [self.am popView:self.inputPasswordView startLocation:JWAnimationLocation_Bottom endLocation:JWAnimationLocation_Center tapMaskBlock:^{
        
    }];
    [self.passwordTextField becomeFirstResponder];
}


- (IBAction)cannelClick:(UIButton *)sender {
    
    if (CannelHostNameTag == sender.tag) {
        [self.am removeViewFromPopView:self.hostNameView toLocation:JWAnimationLocation_Bottom complationBlock:^{
            
        }];
        return;
    }
    [self.am removeViewFromPopView:self.inputPasswordView toLocation:JWAnimationLocation_Bottom complationBlock:^{
    }];
    
    
}

- (IBAction)sureBtnClick:(id)sender {
    [self.am removeViewFromPopView:self.inputPasswordView toLocation:JWAnimationLocation_Bottom complationBlock:^{
        }];
    
    if ([self.passwordTextField.text isEqualToString:@"123456"]) {
        if ([self.title isEqualToString:@"恢复出厂设置"]) {
#warning todo 主机重置用户信息

        }  else {
            [self br_pushViewControllerWithClassName:@"ZSHostExchangeViewController"];
        }
    }  else {
        [self br_AutoDisappearWithText:@"输入密码不正确"];
    }
}

- (IBAction)hostNameChangeSureClick:(id)sender {
    [self.am removeViewFromPopView:self.hostNameView toLocation:JWAnimationLocation_Bottom complationBlock:^{
        
    }];
    
    if(self.hostNameTextField.text.length > 1 && self.hostNameTextField.text.length < 8){
#warning  todo主机名称修改上传请求
    
    } else {
        [self br_AutoDisappearWithText:@"输入内容不能为空, 或过长"];
    }
    
}

- (IBAction)nameChangeBtnClick:(id)sender {
    [self.am popView:self.hostNameView startLocation:JWAnimationLocation_Bottom endLocation:JWAnimationLocation_Center tapMaskBlock:^{
    }];
    [self.hostNameTextField becomeFirstResponder];
}

- (IBAction)wifiForwadClick:(id)sender {
    // 进入WIFI控制器
#warning todo wifi
}

- (void)viewDidLoad {
    [super viewDidLoad];
    [self init_addTapViewEndEdit];
    self.title = @"主机设置";
    
    self.resetBtn.layer.borderColor = [UIColor grayColor].CGColor;
    self.resetBtn.layer.borderWidth = 1;
    self.exchangeBtn.layer.borderColor = [UIColor grayColor].CGColor;
    self.exchangeBtn.layer.borderWidth = 1;
    self.hostName.text = self.dic[@"title"];
    self.hostIDLabel.text = self.dic[@"id"];
    
    if (!self.am) {
        self.am = [[JWAnimationManager alloc] init];
        self.am.isPopViewAdaptWindowWidth = YES;
    }
}

@end
